import type { FormSchema } from '@/components/core/schema-form';
import { getDictListApi } from '@/api/sys/dict';

const getDictList = async (dictType: string) => {
  const data = await getDictListApi(dictType);
  return data.map((item) => ({
    label: item.name,
    value: item.code,
  }));
};
export const manageSchemas: FormSchema<API.CreateManageParams>[] = [
  // {
  //   field: 'id',
  //   component: 'Input',
  //   label: '主键',
  //   rules: [{ required: true, type: 'string' }],
  //   colProps: {
  //     span: 12,
  //   },
  // },
  // {
  //   field: 'name',
  //   component: 'Input',
  //   label: '名称',
  //   rules: [{ required: true, type: 'string' }],
  //   colProps: {
  //     span: 20,
  //   },
  // },
  {
    field: 'equipmentType',
    component: 'Input',
    label: '型号',
    rules: [{ required: true, type: 'string' }],
    colProps: {
      span: 20,
    },
  },
  {
    field: 'manufacturer',
    component: 'Select',
    label: '厂商',
    required: true,
    componentProps: {
      // more details see /src/components/Form/src/components/ApiSelect.vue
      request: async (values) => {
        console.log('field30 fetch', values);
        return await getDictList('MODEL_MANUFACTURER');
      },
      onChange: (e) => {
        console.log('selected:', e);
      },
    },
    colProps: {
      span: 10,
    },
  },

  {
    field: 'metersType',
    component: 'Select',
    label: '水表类型',
    required: true,
    componentProps: {
      // more details see /src/components/Form/src/components/ApiSelect.vue
      request: async (values) => {
        console.log('field30 fetch', values);
        return await getDictList('MODEL_METERSTYPE');
      },
    },
    colProps: {
      span: 10,
    },
  },
  {
    field: 'caliber',
    component: 'Input',
    label: '口径',
    rules: [{ required: true, type: 'string' }],
    colProps: {
      span: 10,
    },
  },

  {
    field: 'agreement',
    component: 'Select',
    label: '协议',
    required: true,
    componentProps: {
      // more details see /src/components/Form/src/components/ApiSelect.vue
      request: async (values) => {
        console.log('field30 fetch', values);
        return await getDictList('MODEL_AGREEMENT');
      },
    },
    colProps: {
      span: 10,
    },
  },
  {
    field: 'collectInterval',
    component: 'Input',
    label: '采集间隔',
    colProps: {
      span: 10,
    },
    rules: [{ required: true }],
    componentSlots: (values) => {
      console.log('field2 componentSlots values', values);
      return {
        suffix: () => '秒',
      };
    },
  },
  {
    field: 'timeoutTime',
    component: 'Input',
    label: '超时时间',
    colProps: {
      span: 10,
    },
    rules: [{ required: true }],
    componentSlots: (values) => {
      console.log('field2 componentSlots values', values);
      return {
        suffix: () => '秒',
      };
    },
  },

  {
    field: 'description',
    component: 'InputTextArea',
    label: '描述',
    rules: [{ required: true, type: 'string' }],
    colProps: {
      span: 20,
    },
  },
];
